package com.fr.data.core.db.tableObject;

import com.fr.data.core.db.dialect.Dialect;
import java.sql.Connection;

public class Column
{
  private String name = "Column";
  private boolean isPrimaryKey = false;
  private Object defaultValue = null;
  private ColumnSize columnSize = new ColumnSize();
  private boolean allowNull = true;
  private int valueType = 12;
  private boolean selfIncrease = false;
  private boolean isForeignKey = false;

  public Column()
  {
  }

  public Column(String paramString, int paramInt, ColumnSize paramColumnSize)
  {
    setName(paramString);
    setValueType(paramInt);
    setColumnSize(paramColumnSize);
  }

  public Column(String paramString, int paramInt, ColumnSize paramColumnSize, Object paramObject, boolean paramBoolean1, boolean paramBoolean2, boolean paramBoolean3, boolean paramBoolean4)
  {
    setName(paramString);
    setValueType(paramInt);
    setColumnSize(paramColumnSize);
    setDefaultValue(paramObject);
    setPrimaryKey(paramBoolean2);
    setAllowNull(paramBoolean1);
    setForeignKey(paramBoolean3);
    setSelfIncrease(paramBoolean4);
  }

  public boolean isForeignKey()
  {
    return this.isForeignKey;
  }

  public void setForeignKey(boolean paramBoolean)
  {
    this.isForeignKey = paramBoolean;
  }

  public boolean isPrimaryKey()
  {
    return this.isPrimaryKey;
  }

  public void setPrimaryKey(boolean paramBoolean)
  {
    this.isPrimaryKey = paramBoolean;
  }

  public Object getDefaultValue()
  {
    return this.defaultValue;
  }

  public void setDefaultValue(Object paramObject)
  {
    this.defaultValue = paramObject;
  }

  public ColumnSize getColumnSize()
  {
    return this.columnSize;
  }

  public void setColumnSize(ColumnSize paramColumnSize)
  {
    this.columnSize = paramColumnSize;
  }

  public boolean isAllowNull()
  {
    return this.allowNull;
  }

  public void setAllowNull(boolean paramBoolean)
  {
    this.allowNull = paramBoolean;
  }

  public String getName()
  {
    return this.name;
  }

  public void setName(String paramString)
  {
    this.name = paramString;
  }

  public int getValueType()
  {
    return this.valueType;
  }

  public void setValueType(int paramInt)
  {
    this.valueType = paramInt;
  }

  public boolean isSelfIncrease()
  {
    return this.selfIncrease;
  }

  public void setSelfIncrease(boolean paramBoolean)
  {
    this.selfIncrease = paramBoolean;
  }

  public String toSQL(Dialect paramDialect, Connection paramConnection, String paramString)
  {
    StringBuffer localStringBuffer = new StringBuffer();
    String str = paramDialect.columnType2SQL(getValueType(), getColumnSize().toString());
    localStringBuffer.append(paramDialect.column2SQL(getName())).append(" ");
    if (isSelfIncrease())
    {
      localStringBuffer.append(paramDialect.createSequence(paramConnection, paramString, paramDialect.column2SQL(getName()), str));
    }
    else
    {
      localStringBuffer.append(str).append(" ");
      if (getDefaultValue() != null)
      {
        localStringBuffer.append("DEFAULT").append(" ");
        if (getDefaultValue() instanceof String)
          localStringBuffer.append("'").append(getDefaultValue()).append("'");
        else
          localStringBuffer.append(getDefaultValue());
      }
      localStringBuffer.append(" ").append((isAllowNull()) ? "NULL" : "NOT NULL");
    }
    return localStringBuffer.toString();
  }
}